package com.tanhua.admin.controller;

import com.tanhua.admin.service.AnalysisService;
import com.tanhua.model.vo.AnalysisSummaryVo;
import com.tanhua.model.vo.YearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private AnalysisService analysisService;

    /**
     * 首页统计
     * @return
     */
    @GetMapping("/summary")
    public ResponseEntity summary(){
        AnalysisSummaryVo vo = analysisService.summary();
        return ResponseEntity.ok(vo);
    }

    /**
     * 新增、活跃用户、次日留存率
     */
    @GetMapping("/users")
    public ResponseEntity analysisUsers(@RequestParam(name = "sd") Long sd,
                                @RequestParam(name = "ed") Long ed,
                                Integer type) {
        Date startDate = new Date(sd);
        Date endDate = new Date(ed);
        YearVo yearVo = analysisService.analysisUsers(startDate, endDate, type);
        return ResponseEntity.ok(yearVo);
    }
}

